package com.ankang.art.controller;


import com.ankang.art.dto.ExamineeDto;
import com.ankang.art.dto.QueryStudentDto;
import com.ankang.art.pto.ExamineePto;
import com.ankang.art.service.ExamineeService;
import com.ankang.art.vo.Examinee;
import org.apache.http.protocol.HTTP;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/art/management/sts")
@CrossOrigin
public class ExamineeController {

    @Autowired
    private ExamineeService examineeService;


    //按照条件查询考生信息
    @GetMapping("getExaminees")
    public ResponseEntity getExaminees(@RequestParam(name = "pageNo",required = false,defaultValue = "1")Integer pageNo,
                                       @RequestParam(name = "pageSize",required = false,defaultValue = "10")Integer pageSize,
                                       @RequestParam(value = "name",required = false) String name,
                                       @RequestParam(value = "gender",required = false) Integer gender,
                                       @RequestParam(value = "idCard",required = false) String idCard,
                                       @RequestParam(value = "schoolName",required = false) String schoolName,
                                       @RequestParam(value = "status",required = false) String status){



        List<Examinee> ExamineePto =  examineeService.getExaminees(pageNo,pageSize,name,gender,idCard,schoolName,status);

        return new ResponseEntity(ExamineePto, HttpStatus.OK);

    }



    //删除考生信息
    @GetMapping("deleteExaminees")
    public ResponseEntity deleteExaminees(@RequestParam(name="idCard",required = false)String idCard){
        boolean flag = examineeService.deleteExaminees(idCard);
        if(flag){
            return new ResponseEntity(HttpStatus.OK);
        }else {
            return new ResponseEntity(HttpStatus.FAILED_DEPENDENCY);
        }

    }


    //添加考生信息
    @PostMapping("saveExaminees")
    public ResponseEntity savaExaminees(@RequestBody ExamineeDto examineeDto){
        boolean flag = examineeService.saveExaminees(examineeDto);
        if(flag){
            return new ResponseEntity(HttpStatus.OK);
        }else {
            return new ResponseEntity(HttpStatus.FAILED_DEPENDENCY);
        }
    }

    //编辑考生信息
    @PostMapping("updateExaminees")
    public ResponseEntity updateExaminees(@RequestBody ExamineeDto examineeDto){
        boolean flag = examineeService.updateExaminees(examineeDto);
        if(flag){
            return new ResponseEntity(HttpStatus.OK);
        }else {
            return new ResponseEntity(HttpStatus.FAILED_DEPENDENCY);
        }
    }


    @GetMapping("getExamTest")
    public ResponseEntity getExamTest(){
        List<Examinee> examineesList = examineeService.getExamTest();
        return new ResponseEntity(examineesList, HttpStatus.OK);
    }


    @GetMapping("addExamTest")
    public ResponseEntity addExamTest(){
        List<Examinee> examineesList = examineeService.addExamTest();
        return new ResponseEntity(examineesList, HttpStatus.OK);
    }


}
